<template>
	<el-dialog
		:title="title"
		:visible.sync="addComShow"
		width="50%"
		:before-close="cancel"
		:close-on-click-modal="false"
		:close-on-press-escape="false"
	>
		<el-form label-width="140px" label-position="left">
			<el-form-item label="统一社会信用编码" required>
				<el-select
					v-model="managementInfo.lawFirmRegisterNumber"
					filterable
					remote
					@change="registerNumberChange"
					reserve-keyword
					placeholder="请输入关键词"
					:remote-method="remoteMethod"
					:loading="loading"
					style="width: 100%"
				>
					<el-option v-for="(item, index) in compintroductionList" :key="index" :value="item.registernumber">
						<span>{{ item.registernumber }}-{{ item.compName }}</span>
					</el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="律师事务所名称" required>
				<el-input v-model.trim="managementInfo.lawFirmName" type="text" :disabled="isDisabled" @input="refresh"></el-input>
			</el-form-item>
			<el-form-item label="律师事务所英文名称">
				<el-input v-model.trim="managementInfo.lawFirmEnglishName" type="text" :disabled="isDisabled" @input="refresh"></el-input>
			</el-form-item>
			<el-form-item label="经办律师名称">
				<el-input v-model.trim="managementInfo.handleLawerName" type="text" :disabled="isDisabled" @input="refresh"></el-input>
			</el-form-item>
		</el-form>
		<span slot="footer" class="dialog-footer">
			<el-button size="small" @click="cancel">取 消</el-button>
			<el-button size="small" type="primary" @click="addConfirm">确 定</el-button>
		</span>
	</el-dialog>
</template>
<script>
import { addLawFirmList, editLawFirmList } from '@/api/productApi/mechanism'
import { getCompintroduction } from '@/api/productApi/file'
import { EmptyJudgment } from '@/utils/validate'
export default {
	props: {
		title: {
			type: String,
			default: ''
		},
		addComShow: {
			type: Boolean,
			default: false
		},
		comIsShow: {
			type: Function,
			default: Function
		},
		queryFundManagerList: {
			type: Function,
			default: Function
		}
	},
	data() {
		return {
			managementInfo: {
				lawFirmRegisterNumber: ''
			},
			isDisabled: false,
			compintroductionList: [],
			paging: {
				size: 20, // 显示的条目数
				num: 1 // 当前页数
			},
			sInfoComptype: '28', // 默认查询：万德公司类型(28:律师事务所)
			loading: false
		}
	},
	mounted() {},
	methods: {
		cancel() {
			this.$emit('comIsShow')
			this.managementInfo = {
				lawFirmRegisterNumber: ''
			}
		},
		remoteMethod(query) {
			this.managementInfo.lawFirmRegisterNumber = query
			this.remoteMethodList(query)
		},
		// 新增或编辑
		addConfirm() {
			if (EmptyJudgment(this.managementInfo.lawFirmRegisterNumber) || EmptyJudgment(this.managementInfo.lawFirmName)) {
				this.$message({
					type: 'warning',
					message: '请填写必要参数'
				})
				return
			}
			if (this.title === '新增') {
				addLawFirmList({ lawFirmInfo: this.managementInfo }).then(res => {
					if (res.msgCode === 'Y') {
						this.cancel()
						this.$emit('queryFundManagerList')
						this.$message({ message: res.msgDesc, type: 'success' })
					}
				})
			} else if (this.title === '修改') {
				editLawFirmList({ lawFirmId: this.managementInfo.lawFirmId, lawFirmInfo: this.managementInfo }).then(res => {
					if (res.msgCode === 'Y') {
						this.cancel()
						this.$emit('queryFundManagerList')
						this.$message({ message: res.msgDesc, type: 'success' })
					}
				})
			}
		},
		refresh() {
			this.$forceUpdate()
		},
		registerNumberChange() {
			const compInfo = this.compintroductionList.filter(item => item.registernumber === this.managementInfo.lawFirmRegisterNumber)
			if (compInfo.length) {
				// 万德公司ID
				this.$set(this.managementInfo, 'wdComId', compInfo[0].compId)
				// 律师事务所代码
				this.$set(this.managementInfo, 'lawFirmRegisterNumber', compInfo[0].registernumber)
				// 律师事务所名称
				this.$set(this.managementInfo, 'lawFirmName', compInfo[0].compName)
				// 律师事务所英文名称
				this.$set(this.managementInfo, 'lawFirmEnglishName', compInfo[0].compNameEng)
				// 经办律师名称
				// this.managementInfo.handleLawerName=compInfo===""||compInfo===null?"":compInfo.;
			}
		},
		edit(obj) {
			this.managementInfo = JSON.parse(obj)
		},
		// 查询：万德公司信息
		remoteMethodList(value) {
			if (value) {
				const params = {}
				// 搜索参数
				params.sInfoComptypes = '28'
				params.compIdOrName = value
				this.loading = true
				getCompintroduction(params, this.paging).then(res => {
					if (res.msgCode === 'Y') {
						// 万德公司信息
						this.compintroductionList = res.data.body.data.body
						this.registerNumberChange()
					}
					this.loading = false
				})
			}
		}
	}
}
</script>
<style lang="scss" scoped >
::v-deep .el-textarea__inner {
	height: 203px;
}
</style>
